package com.yequan.designpattern.singleton.EnumFactory;

/**
 * @Auther: yq
 * @Date: 2019/1/11 13:03
 * @Description:
 */
public class EnumSingleFactory {

    /**
     * 枚举的方式实现单例模式（线程安全）
     * 解决暴露枚举类问题，遵循单一职责原则
     */
    private enum EnumSingleton {
        singletonFactory;
        private SEnumSingleton instance;

        private EnumSingleton() {
            try {
                Thread.sleep(300);
                instance = new SEnumSingleton();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        public SEnumSingleton getInstance() {
            return instance;
        }
    }

    public static SEnumSingleton getInstance() {
        return EnumSingleton.singletonFactory.instance;
    }

}

class SEnumSingleton {
    public SEnumSingleton() {
    }
}
